package state

import (
	"fmt"
	"utilx/logx"
)

type HasMoneyState struct {
	vendingMachine *VendingMachine
}

func (i *HasMoneyState) name() string {
	return "HasMoneyState"
}
func (i *HasMoneyState) requestItem() error {
	return fmt.Errorf("Item dispense in progress")
}

func (i *HasMoneyState) addItem(count int) error {
	return fmt.Errorf("Item dispense in progress")
}

func (i *HasMoneyState) insertMoney(money int) error {
	return fmt.Errorf("Item out of stock")
}
func (i *HasMoneyState) dispenseItem(count int) error {
	logx.Info("HasMoneyState Dispensing Item")
	i.vendingMachine.itemCount = i.vendingMachine.itemCount - count
	if i.vendingMachine.itemCount <= 0 {
		i.vendingMachine.SetCurrentState(i.vendingMachine.noItem)
	} else {
		i.vendingMachine.SetCurrentState(i.vendingMachine.hasItem)
	}
	return nil
}
